#! /bin/sh
LINE=`xrandr -q | grep Screen`
HEIGHT=`echo ${LINE} | awk '{ print $10 }' | awk -F"," '{ print $1 }'`
WIDTH=`echo ${LINE} | awk '{ print $8 }'`

if [ $(pgrep -cx panel) -gt 1 ] ; then
	printf "%s\n" "The panel is already running." >&2
	exit 1
fi

trap 'trap - TERM; kill 0' INT TERM QUIT EXIT

[ -e "$PANEL_FIFO" ] && rm "$PANEL_FIFO"
mkfifo "$PANEL_FIFO"

bspc config top_padding $PANEL_HEIGHT
bspc control --subscribe > "$PANEL_FIFO" &
xtitle -sf 'T%s' > "$PANEL_FIFO" &
clock -sf 'S%a %H:%M' > "$PANEL_FIFO" &
mpc current > "$PANEL_FIFO" &
. panel_colors

cat "$PANEL_FIFO" | panel_bar | lemonbar -g $(($WIDTH-14))x20+7+5 -f "Tewi-9" -F "$COLOR_FOREGROUND" -B "$COLOR_BACKGROUND" &

wait
